﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 飞行棋
{
    class Program
    {
        //定义两个玩家的名称
        private static string[] playername = new string[2];
        static int[] maps = new int[100];//地图
        static int[] playerwj = new int[2];//玩家位置
        static bool[] flag = new bool[2];//代表谁筛筛子，谁false谁走
        static void Main(string[] args)
        {
            wegame();
            #region 玩家输入姓名
            Console.ForegroundColor = ConsoleColor.White;//设置背景色为白色
            Console.WriteLine("请输入玩家A的名称：");
            playername[0] = Console.ReadLine();
            while (playername[0] == string.Empty)//判空
            {
                Console.WriteLine("玩家A的名称不能为空，请从新输入");
                playername[0] = Console.ReadLine();
            }
            Console.WriteLine("请输入玩家B的名称：");
            playername[1] = Console.ReadLine();
            while (playername[0] == string.Empty || playername[0] == playername[1])
            {
                if (playername[0] == string.Empty)
                    Console.WriteLine("玩家B的名称不能为空，请从新输入");
                else if (playername[0] == playername[1])
                    Console.WriteLine("玩家B的名称不能与A相同，请从新输入");
                playername[0] = Console.ReadLine();
            }
            #endregion
            Console.Clear();//清屏
            wegame();
            //Console.WriteLine("{0}的飞机用A来表示", playername[0]);
            //Console.WriteLine("{0}的飞机用B来表示", playername[1]);
            gogame();
            huamaps();
            while (playerwj[0] < 99 && playerwj[1] < 99)
            {
                #region A号玩家行动
                if (flag[0] == false)
                {
                    yaoshaizhi(0);
                }
                else
                {
                    flag[0] = false;
                }
                if (playerwj[0] >= 99)
                {
                    Console.WriteLine("玩家{0}无耻的赢了玩家{1}", playername[0], playername[1]);
                    break;
                }
                #endregion
                #region B号玩家行动
                if (flag[0] == false)
                {
                    yaoshaizhi(1);
                }
                else
                {
                    flag[0] = false;
                }
                if (playerwj[0] >= 99)
                {
                    Console.WriteLine("玩家{0}无耻的赢了玩家{1}", playername[1], playername[0]);
                    break;
                }
                #endregion
            }
            win();
            Console.ReadKey();
        }

        public static void yaoshaizhi(int play)//扔骰子后判断效果和行动
        {
            Console.WriteLine("{0}按任意键开始扔骰子", playername[play]);
            Console.ReadKey(true);
            Random r = new Random();
            int rnumber = r.Next(1, 7);
            Console.WriteLine("{0}扔除了{1}", playername[play], rnumber);
            playerwj[play] += rnumber;
            pdwj();
            Console.ReadKey(true);
            Console.WriteLine("{0}按任意键开始行动", playername[play]);
            Console.ReadKey(true);
            Console.WriteLine("{0}行动完了", playername[play]);
            Console.ReadKey(true);
            if (playerwj[play] == playerwj[1 - play])
            {
                playerwj[1 - play] = playerwj[1 - play] - 6;
                pdwj();
                Console.ReadKey(true);
            }
            else
            {
                switch (maps[playerwj[play]])
                {
                    case 0:
                        Console.WriteLine("玩家{0}踩到了方块，安全。", playername[play]);
                        Console.ReadKey(true);
                        break;
                    case 1:
                        Console.WriteLine("玩家{0}踩到了幸运轮盘，请选择1—交换位置，2—轰炸对方。", playername[play]);
                        string input = Console.ReadLine();
                        while (true)
                        {
                            if (input == "1")
                            {
                                Console.WriteLine("玩家{0}选择了与玩家{1}交换位置", playername[play], playername[1 - play]);
                                Console.ReadKey(true);
                                int t = playerwj[play];
                                playerwj[play] = playerwj[1 - play];
                                playerwj[1 - play] = t;
                                Console.WriteLine("交换完成！！！继续游戏！！！");
                                Console.ReadKey(true);
                                break;
                            }
                            else if (input == "2")
                            {
                                Console.WriteLine("玩家{0}选择了轰炸玩家{1}，玩家{2}退6格", playername[play], playername[1 - play], playername[1 - play]);
                                Console.ReadKey(true);
                                playerwj[1 - play] -= 6;
                                pdwj();
                                Console.WriteLine("玩家{0}退后了6格", playername[1 - play]);
                                Console.ReadKey(true);
                                break;
                            }
                            else
                            {
                                Console.WriteLine("只能输入1或者2，1—交换位置，2—轰炸对方。");
                                input = Console.ReadLine();
                            }
                        }
                        break;
                    case 2:
                        Console.WriteLine("玩家{0}踩到了地雷，退后6格", playername[play]);
                        Console.ReadKey(true);
                        playerwj[play] -= 6;
                        pdwj();
                        Console.WriteLine("玩家{0}退后了6格", playername[play]);
                        Console.ReadKey(true);
                        break;
                    case 3:
                        Console.WriteLine("玩家{0}踩到了暂停，暂停一回合", playername[play]);
                        flag[play] = true;
                        Console.ReadKey(true);
                        break;
                    case 4:
                        Console.WriteLine("玩家{0}踩到了时空隧道，前进10格", playername[play]);
                        playerwj[play] += 10;
                        pdwj();
                        Console.ReadKey(true);
                        break;
                    default:
                        break;
                }
            }
            pdwj();
            Console.Clear();
            huamaps();
        }

        public static void pdwj()//判断玩家是否超出地图
        {
            if (playerwj[0] < 0)
            {
                playerwj[0] = 0;
            }
            if (playerwj[0] >= 99)
            {
                playerwj[0] = 99;
            }
            if (playerwj[0] < 0)
            {
                playerwj[0] = 0;
            }
            if (playerwj[0] >= 99)
            {
                playerwj[0] = 99;
            }
        }
        public static void gogame()//设置地图特殊效果
        {
            //幸运轮盘★
            int[] luckyturn = { 6, 16, 23, 29, 40, 55, 68, 73, 83 };
            for (int i = 0; i < luckyturn.Length; i++)
            {
                maps[luckyturn[i]] = 1;
            }
            //地雷◎
            int[] dilei = { 5, 13, 17, 22, 33, 38, 44, 50, 64, 80, 94, 95, 96 };
            for (int i = 0; i < dilei.Length; i++)
            {
                maps[dilei[i]] = 2;
            }
            //停止●
            int[] tingxia = { 9, 27, 34, 60, 93, 2, 3, 4, 7, 8, 92, 93 };
            for (int i = 0; i < tingxia.Length; i++)
            {
                maps[tingxia[i]] = 3;
            }
            //时空隧道※
            int[] luckytime = { 20, 25, 63, 72, 88, 90 };
            for (int i = 0; i < luckytime
                .Length; i++)
            {
                maps[luckytime[i]] = 4;
            }
        }

        public static void huamaps()//画地图
        {
            Console.WriteLine("{0}的飞机用A来表示", playername[0]);
            Console.WriteLine("{0}的飞机用B来表示", playername[1]);
            Console.WriteLine("地图说明：幸运轮盘：★   地雷：◎   停留：●    时空隧道：※");
            #region 第一行
            for (int i = 0; i < 30; i++)
            {
                Console.Write(mapstuan(i));
            }
            #endregion
            Console.WriteLine();//换行
            #region 第一竖列
            for (int i = 30; i < 35; i++)
            {
                for (int j = 0; j <= 28; j++)
                {
                    Console.Write("  ");
                }
                Console.Write(mapstuan(i));
                Console.WriteLine();
            }
            #endregion
            #region 第二行
            for (int i = 35; i < 65; i++)
            {
                Console.Write(mapstuan(i));
            }
            #endregion
            Console.WriteLine();
            #region 第二竖列
            for (int i = 65; i < 70; i++)
            {
                Console.Write(mapstuan(i));
                for (int j = 1; j <= 29; j++)
                {
                    Console.Write("  ");
                }
                Console.WriteLine();
            }
            #endregion
            #region 第三行
            for (int i = 70; i < 100; i++)
            {
                Console.Write(mapstuan(i));
            }
            #endregion
            Console.WriteLine();
        }

        public static string mapstuan(int i)//在地图上显示的效果
        {
            string str = "";
            if (playerwj[0] == playerwj[1] && playerwj[0] == i)
            {
                str = "<>";
            }
            else if (playerwj[0] == i)
            {
                str = "A";
            }
            else if (playerwj[1] == i)
            {
                str = "B";
            }
            else
            {
                switch (maps[i])
                {
                    case 0:
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        str = "□";
                        break;
                    case 1:
                        Console.ForegroundColor = ConsoleColor.Red;
                        str = "★";
                        break;
                    case 2:
                        Console.ForegroundColor = ConsoleColor.Green;
                        str = "◎";
                        break;
                    case 3:
                        Console.ForegroundColor = ConsoleColor.White;
                        str = "●";
                        break;
                    case 4:
                        Console.ForegroundColor = ConsoleColor.Red;
                        str = "※";
                        break;
                }
            }
            return str;
        }
        public static void wegame()//初始界面
        {
            //设置背景色
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("******************");
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("**简单飞行棋游戏**");
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("******************");
        }

        public static void win()
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("游戏结束！！！！");
            Console.WriteLine("按1后任意键退出界面");
            string input = Console.ReadLine();
            while (true)
            {
                if (input == "1")
                {
                    break;
                }
                else
                {
                    input = Console.ReadLine();
                }
            }
        }
    }
}
